<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <title>云APIs</title>
    <link rel="stylesheet" type="text/css" href="../css/api.css"/>
    <link rel="stylesheet" type="text/css" href="../css/style.css"/>
    <style>
    body{background:#EFEFF4;}
        .empty{ text-align: center; padding: 120px 0; }
        .list_content_padded {padding: 10px 10px 0}
.item_data {
    border: 1px solid #ccc;
    background: #fff;
    padding: 10px;
	margin-bottom:10px;
    overflow: hidden;
}
.item_data h3 {
    width: 100%;
    height: 50px;
    line-height: 50px;
    text-align: center;
    font-size: 18px;
}
.list_button {
    width: 100%;
    height: 50px;
    border: 0;
    border-radius: 5px;
    background: #ec6d65;
    color: #fff;
    font-size: 18px;
}

.list_input {
    background: #474956;
    height: 50px;
    width: 100%;
    color: #fff;
    box-sizing: border-box;
    border: 0;
    border-radius: 5px;
    font-size: 16px;
    padding: 0 0 0 15px;
}

.text_input .list_input {
    width: 75%;
    float: left;
}
.text_input .list_button {
    width: 20%;
    float: right;
    font-size: 16px;
}
.index_detail_show {
    position: absolute;
    top: 0;
    padding: 44px 0 0;
    left: 0;
    z-index: 20;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,.7);
    /*display: none;*/
}
.list_content_padded {
    padding: 0 10px;
}
.item_data {
    border: 1px solid #ccc;
    background: #fff;
    padding: 10px;
    margin-top: 10px;
    overflow: hidden;
}
.index_detail_show ul li {
    line-height: 42px;
    position: relative;
}
.index_detail_show ul li:before {
    position: absolute;
    right: 0;
    bottom: 0;
    left: 0;
    height: 1px;
    content: '';
    -webkit-transform: scaleY(.5);
    transform: scaleY(.5);
    background-color: #c8c7cc;
}
.index_detail_show #off_back {
    width: 45%;
    float: left;
    margin-top: 20px;
}
.index_detail_show #confirm_use {
    width: 45%;
    float: right;
    margin-top: 20px;
}
.no_used{color:red;}


    </style>
</head>
<body>
    <div class="index_detail_show">
        <div class="list_content_padded">
            <div class=" item_data">
                <ul class="">
                    <li class="">
                            商家名称: <span class="vender_name" id="verify_vender_name">null</span>
                    </li>
                    <li class="">
                            商品名称: <span class="goods_name" id="verify_goods_name">null</span>
                    </li>
                    <li class="">
                            商品金额: <span class="goods_price" id="verify_goods_price">null</span>
                    </li>
                    <li class="">
                            手&nbsp;&nbsp;机&nbsp;&nbsp;号: <span class="phone" id="verify_phone">null</span>
                    </li>
                    <li class="">
                            订单时间: <span class="order_time" id="verify_order_time">null</span>
                    </li>
                    <li class="">
                            使用状态: <span class="is_use" class="" id="verify_is_use">null</span>
                    </li>
                    <!--<li class="">
                            支付金额: <span class="use_time">80元</span>
                    </li>-->
                </ul>
            </div>
            <button id='off_back' class="list_button " onclick="closeWindows();">返回</button>
            <button id='confirm_use' class="list_button" onclick="useVerifyFnBegin();">确认使用</button>
        </div>
    </div>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/urlpath.js"></script>
<script>
    var verify_snes = null;
    apiready = function () {
        var verify_sns = api.pageParam.verify_sn;
        queryVerifyFn(verify_sns);
        verify_snes = verify_sns;
    }
    $api.addEvt($api.byId("off_back"), 'touchstart', function(e) {
        $api.css($api.byId("off_back"),'background:#F9817A;');
    });
    $api.addEvt($api.byId("off_back"), 'touchend', function(e) {
        $api.css($api.byId("off_back"),'background:#ec6d65;');
    });
    $api.addEvt($api.byId("confirm_use"), 'touchstart', function(e) {
        $api.css($api.byId("confirm_use"),'background:#F9817A;');
    });
    $api.addEvt($api.byId("confirm_use"), 'touchend', function(e) {
        $api.css($api.byId("confirm_use"),'background:#ec6d65;');
    });
    function closeWindows(){
        api.closeWin();
    }
    function queryVerifyFn(num){
        api.showProgress({
            style: 'default',
            animationType: 'fade',
            title: '努力加载中...',
            text: '请稍候...',
            modal: false
        });
        api.ajax({
            url: URLpath+'/ajax/call/vender_admin/verify_info',
            method: 'post',
            data: {
                values: { 
                    "verify_sn":num
                }
            }
        },function(ret, err){
            api.hideProgress();
            if(!ret || ret.errno ){
                // alert(ret.errmsg);
                api.toast({
                    msg: ret.errmsg,
                    duration: 2000,
                    location: 'middle'
                });
                setTimeout(function(){
                    closeWindows();
                },2300);
            }else{
                var res = ret ;
                // $api.byId("verify_writeOff_input").fadeIn();
                // alert("resssss"+JSON.stringify( res ));
                $api.text($api.byId("verify_vender_name"),res.vender_name);
                $api.text($api.byId("verify_goods_name"),res.goods_name);
                $api.text($api.byId("verify_goods_price"),res.goods_price);
                $api.text($api.byId("verify_phone"),res.phone);
                $api.text($api.byId("verify_order_time"),res.order_time);
                if(res.left_count){
                    $api.text($api.byId("verify_is_use"),res.left_count);
                }else{
                    if(res.is_use == 0 ){
                        $api.text($api.byId("verify_is_use"),'未使用');
                        $api.addCls($api.byId("verify_is_use"), 'no_used');
                    }else if(res.is_use == 1 ){
                        $api.text($api.byId("verify_is_use"),'已使用');
                    }
                }
            }
        });
    }
    function useVerifyFnBegin(){
        api.confirm({
            title: '系统提示',
            msg: '确定要进行核销吗？',
            buttons: ['取消', '确定']
        },function( ret, err ){
            if( ret ){
                 if(ret.buttonIndex == "1"){
                    
                 }else{
                    useVerifyFn(verify_snes);
                 }
            }else{
                 // alert( JSON.stringify( ret ) );
            }
        });
    }
    function useVerifyFn(num){
        api.showProgress({
            style: 'default',
            animationType: 'fade',
            title: '努力加载中...',
            text: '请稍候...',
            modal: false
        });
        api.ajax({
            url: URLpath+'/ajax/call/vender_admin/verify_use',
            method: 'post',
            data: {
                values: { 
                    "verify_sn":num
                }
            },
            timeout:5
        },function(ret, err){
            api.hideProgress();
            if (ret) {
                if(!ret || ret.errno ){
                    // alert(ret.errmsg);
                    api.toast({
                        msg: ret.errmsg,
                        duration: 2000,
                        location: 'middle'
                    });
                    setTimeout(function(){
                        closeWindows();
                    },2300);
                }else{
                    var res = ret ;
                    if(res.left_count){
                        $api.text($api.byId("verify_is_use"),res.left_count);
                    }else{
                        if(res.is_use == 0 ){
                            $api.text($api.byId("verify_is_use"),'未使用');
                        }else if(res.is_use == 1 ){
                             $api.text($api.byId("verify_is_use"),'已使用');
                        }
                    }
                    api.toast({
                        msg: '核销成功',
                        duration: 2000,
                        location: 'middle'
                    });
                    // closeWindows();
                    setTimeout(function(){
                        closeWindows();
                    }, 2500);
                }
            } else {
                api.confirm({
                    title: '系统提示',
                    msg: '网络请求超时，下拉刷新试试？',
                    buttons: ['确定']
                },function( ret, err ){
                    
                });
            }
        });
    }
</script>
</html>